import Tag from "@model/entity/Tag/Tag"
/* util */
import { userChartInitDate, getDefaultDimension } from '@hooks/useChartIndex'

export enum ChartsSearchTimePeriodTypeEnum {
  Date = 'date',
  Week = 'week',
  Month = 'month',
  Quarter = 'quarter',
  Year = 'year'
}

export type ChartsSearchTimePeriodType = {
  // 开始时间
  startTime?: string;
  // 结束时间
  endTime?: string;
  // 时间周期开始日期数据
  startDate?: Date;
  // 时间周期结束日期数据
  endDate?: Date;
  // 时间周期类型
  type: ChartsSearchTimePeriodTypeEnum;  
}

/** 
 * @description 图表搜索参数类型
*/
export type ChartsSearchParamsType = {
  // 工单类型id列表
  taskTypeIds: string[];
  // 用户id列表
  userIds: string[];
  // 团队部门id列表
  tagIds: string[];
  // 团队列表
  tags: Tag[];
  // 开始时间
  timeStart?: string;
  // 结束时间
  timeEnd?: string;
  // 时间周期开始日期数据
  periodStartDate?: Date;
  // 时间周期结束日期数据
  periodEndDate?: Date;
  // 时间周期类型
  type: ChartsSearchTimePeriodTypeEnum;  
  // 仓库id
  repertoryIdList?: string;
  // 备件品类id
  sparepartIdList?: string[];
  // 服务类型id
  serviceTypeList?: string[];
  // 需要隐藏的周期类型
  hidePeriodList?: string[];
}

/** 
 * @description 图表搜索参数类
*/
export class ChartsSearchParams {
  // 工单类型id列表
  public taskTypeIds: string[] = []
  // 用户id列表
  public userIds:string[] = []
  // 团队部门id列表
  public tagIds: string[] = []
  // 团队部门列表
  public tags: Tag[] = []
  // 开始时间
  public timeStart?:string = undefined
  // 结束时间
  public timeEnd?:string = undefined
  // 时间周期开始日期数据
  public periodStartDate?: Date = undefined
  // 时间周期结束日期数据
  public periodEndDate?: Date = undefined
  // 时间周期类型
  public type: ChartsSearchTimePeriodTypeEnum = ChartsSearchTimePeriodTypeEnum.Date;
  // 仓库id
  public repertoryIdList?: string = undefined
  // 备件品类id
  public sparepartIdList?: string[] = undefined
  // 服务类型id
  public serviceTypeList?: string[] = undefined
  // 需要隐藏的周期类型
  public hidePeriodList?: string[] = undefined
  
  constructor(params?: ChartsSearchParamsType) {
    this.taskTypeIds = params?.taskTypeIds || []
    this.userIds = params?.userIds || []
    this.tagIds = params?.tagIds || []
    this.tags = params?.tags || []
    this.timeStart = params?.timeStart || undefined
    this.timeEnd = params?.timeEnd || undefined
    this.periodStartDate = params?.periodStartDate || undefined
    this.periodEndDate = params?.periodEndDate || undefined
    this.type = params?.type || ChartsSearchTimePeriodTypeEnum.Date 
    this.repertoryIdList = params?.repertoryIdList || undefined
    this.sparepartIdList = params?.sparepartIdList || []
    this.serviceTypeList = params?.serviceTypeList || []
    this.hidePeriodList = params?.hidePeriodList || []
  }
  
  /** 
   * @description  设置工单类型id列表
   * @param {string[]} taskTypeIds 工单类型id列表
  */
  setTaskTypeIds(taskTypeIds: string[]) {
    this.taskTypeIds = taskTypeIds
  }
  
  /** 
   * @description  设置用户id列表
   * @param {string[]} userIds 用户id列表
  */
  setUserIds(userIds: string[]) {
    this.userIds = userIds
  }
  
  /** 
   * @description  设置团队id列表
   * @param {string[]} tagIds 团队id列表
  */
  setTagIds(tagIds: string[]) {
    this.tagIds = tagIds
  }
  
  /** 
   * @description  设置开始时间
   * @param {string | undefined} timeStart 开始时间
  */
  setTimeStart(timeStart?: string) {
    this.timeStart = timeStart
  }
  
  /** 
   * @description  设置结束时间
   * @param {string | undefined} timeEnd 结束时间
  */
  setTimeEnd(timeEnd?: string) {
    this.timeEnd = timeEnd
  }
  
}

/** 
 * @description 图表搜索入参(过滤后的)
*/
export type ChartsSearchFetchParamsType = {
  // 部门
  tags: string[];
  // 工单类型
  taskTypes: string[]; 
  // 开始时间
  startTime: string; 
  // 结束时间
  endTime: string; 
  // 统计维度: 0:天 1:周 2:月 3:季度 4:年（默认为周）
  dimension: number;
  // 人员id
  userIdList?: string[];
  // 仓库id
  repertoryIdList?: string[];
  // 备件品类id
  sparepartIdList?: string[];
  // 服务类型id
  serviceTypeList?: string[];
}

/** 
 * @description 图表搜索入参 类(过滤后的)
*/
export class ChartsSearchFetchParams {
  // 部门
  public tags?: string[] = []
  // 工单类型
  public taskTypes?: string[] = [] 
  // 开始时间 初始化搜索时间（默认近30天）
  public startTime?: string = undefined
  // 结束时间
  public endTime?: string = undefined
  // 统计维度: 0:天 1:周 2:月 3:季度 4:年（默认为周）
  public dimension?: number = undefined
  // 人员id
  public userIdList?: string[] = []
  // 仓库id
  public repertoryIdList?: string[] = undefined
  // 备件品类id
  public sparepartIdList?: string[] = []
  // 服务类型id
  public serviceTypeList?: string[] = []

  constructor(chartType: string, params?: ChartsSearchFetchParamsType) {
    this.tags = params?.tags || []
    this.taskTypes = params?.taskTypes || []
    this.startTime = params?.startTime || userChartInitDate(chartType).startTime
    this.endTime = params?.endTime || userChartInitDate(chartType).endTime
    this.dimension = params?.dimension || getDefaultDimension(chartType)
    this.userIdList = params?.userIdList || []
    this.repertoryIdList = params?.repertoryIdList || []
    this.sparepartIdList = params?.sparepartIdList || []
    this.serviceTypeList = params?.serviceTypeList || []
  }
}

/** 
 * @description 下钻table分页参数
*/
export type ChartsTablePageParamsType = {
  // 当前页码
  page: number;
  // 每页显示数量
  pageSize: number;
  // 总数
  totalSize: number;
}

/** 
 * @description 下钻table分页参数类
*/
export class ChartsTablePageParams {
  // 当前页码
  public page?: number = undefined
  // 每页显示数量
  public pageSize?: number = undefined
  // 总数
  public totalSize?: number = undefined

  constructor(params: ChartsTablePageParamsType) {
    this.page = params?.page || 1
    this.pageSize = params?.pageSize || 10
    this.totalSize = params?.totalSize || undefined
  }
}
 
/** 
 * @description 团队排行榜数据类
*/
class TeamRanking {
  public data?: string[] | null = []
  public page?: number | null = 1
  public hasNextPage?: boolean | null = false
  public tagId?: string | null = ''
}

export type ChartsTeamRankingDataType = {
  teamIncome: TeamRanking;
  teamProfit: TeamRanking;
  staffIncome: TeamRanking;
  staffProfit: TeamRanking
}

export class ChartsTeamRankingDataParams {
  // 部门收入排行
  public teamIncome?: TeamRanking = new TeamRanking()
  // 部门利润排行
  public teamProfit?: TeamRanking = new TeamRanking()
  // 人员收入排行
  public staffIncome?: TeamRanking = new TeamRanking()
  // 人员利润排行
  public staffProfit?: TeamRanking = new TeamRanking()
  
  constructor(params?: ChartsTeamRankingDataType) {
    this.teamIncome = params?.teamIncome || new TeamRanking()
    this.teamProfit = params?.teamProfit || new TeamRanking()
    this.staffIncome = params?.staffIncome || new TeamRanking()
    this.staffProfit = params?.staffProfit || new TeamRanking()
  }
}

export type ChartsSparePartsType = {
  spareIncomeProfitData: TeamRanking;
  serviceIncomeProfitData: TeamRanking;
}

export class ChartsSparePartsDataParams {
  // 备件明细
  public spareIncomeProfitData?: TeamRanking = new TeamRanking()
  // 服务项目明细
  public serviceIncomeProfitData?: TeamRanking = new TeamRanking()
  
  constructor(params?: ChartsSparePartsType) {
    this.spareIncomeProfitData = params?.spareIncomeProfitData || new TeamRanking()
    this.serviceIncomeProfitData = params?.serviceIncomeProfitData || new TeamRanking()
  }
}